package com.ZengQi.event.dao.impl;

import com.ZengQi.event.dao.CompanyDao;
import com.ZengQi.event.entity.Company;
import com.ZengQi.event.util.SearchUtils;
import com.ZengQi.event.util.UpdateUtils;

import java.util.List;

public class CompanyDaoImpl implements CompanyDao {
    @Override
    public List<Company> listCompany() {
        String sql="select company_id companyId,company_name companyName,company_key companyKey, company_admin companyAdmin,company_description companyDescription from company ";
        List<Company> companyList = SearchUtils.searchForList(Company.class, sql);
        return companyList;
    }

    @Override
    public boolean deleteCompany(Company conditionCompany) {
        String sql="delete from company where company_name=?";
        boolean update = UpdateUtils.update(sql, conditionCompany.getCompanyName());
        return update;

    }

    @Override
    public boolean insertCompany(Company company) {
        String sql="insert into company values(null,?,?,?,?)";
        boolean update = UpdateUtils.update(sql, company.getCompanyName(), company.getCompanyKey(), company.getCompanyAdmin(), company.getCompanyDescription());
        return update;


    }

    @Override
    public boolean updateCompanyByCompanyName(Company conditionCompany, String oldCompanyName) {
        String sql="update company set company_name=?,company_key=?,company_description =?where company_name=?";
        boolean update = UpdateUtils.update(sql, conditionCompany.getCompanyName(), conditionCompany.getCompanyKey(), conditionCompany.getCompanyDescription(), oldCompanyName);
        return update;
    }


}
